{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c2567930-c5fe-4fc7-8b27-c70411ed47e2",
   "metadata": {
    "ExecutionIndicator": {
     "show": true
    },
    "execution": {
     "iopub.execute_input": "2024-01-15T02:56:10.151095Z",
     "iopub.status.busy": "2024-01-15T02:56:10.150773Z",
     "iopub.status.idle": "2024-01-15T02:56:10.153699Z",
     "shell.execute_reply": "2024-01-15T02:56:10.153275Z",
     "shell.execute_reply.started": "2024-01-15T02:56:10.151078Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "import openai\n",
    "openai.api_key = \"EMPTY\" # Not support yet\n",
    "openai.api_base = \"http://localhost:8000/v1\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8a87140c-72ee-4a2d-8435-f424d0c651ad",
   "metadata": {
    "ExecutionIndicator": {
     "show": true
    },
    "execution": {
     "iopub.execute_input": "2024-01-15T02:56:11.071444Z",
     "iopub.status.busy": "2024-01-15T02:56:11.071135Z",
     "iopub.status.idle": "2024-01-15T02:56:17.422418Z",
     "shell.execute_reply": "2024-01-15T02:56:17.421946Z",
     "shell.execute_reply.started": "2024-01-15T02:56:11.071426Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "completion = openai.ChatCompletion.create(\n",
    "  model='chatglm3-6b',\n",
    "  messages=[{\"role\": \"user\", \"content\": \"Hello! What is your name?\"}]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "83de2a20-d746-43f1-8d1d-8713c5f30acc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-01-15T02:56:23.391606Z",
     "iopub.status.busy": "2024-01-15T02:56:23.391291Z",
     "iopub.status.idle": "2024-01-15T02:56:23.396465Z",
     "shell.execute_reply": "2024-01-15T02:56:23.396077Z",
     "shell.execute_reply.started": "2024-01-15T02:56:23.391584Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<OpenAIObject chat.completion id=chatcmpl at 0x7f8082f6a5c0> JSON: {\n",
       "  \"id\": \"chatcmpl\",\n",
       "  \"model\": \"default-model\",\n",
       "  \"object\": \"chat.completion\",\n",
       "  \"created\": 1705287377,\n",
       "  \"choices\": [\n",
       "    {\n",
       "      \"index\": 0,\n",
       "      \"message\": {\n",
       "        \"role\": \"assistant\",\n",
       "        \"content\": \"Hello! I am an AI assistant named ChatGLM3-6B, which is developed based on the language model jointly trained by Tsinghua University KEG Lab and Zhipu AI Company in 2023. My job is to provide appropriate answers and support to users' questions and requests.\"\n",
       "      },\n",
       "      \"finish_reason\": \"stop\"\n",
       "    }\n",
       "  ],\n",
       "  \"usage\": {\n",
       "    \"prompt_tokens\": 13,\n",
       "    \"completion_tokens\": 66,\n",
       "    \"total_tokens\": 79\n",
       "  }\n",
       "}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "completion"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a07dc426-29ca-48dc-97e7-2e83a9e556cf",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
